javascript: (function () {
	//Localstorage
	try {
		if (localStorage.getItem) {
			storage = localStorage;
		}
		else if (window.localStorage.getItem) {
			storage = window.localStorage;
		}
	}catch(failsafe) {
		//Fall safe for unkown browsers maybe save to cookie store in......
	}
    var DroneLite = {
        Stamina: 0,
        Energy: 0,
        CurrentEnergyJob: 0,
        CurrentStaminaJob: 0,
        Status: "Drone.&#12324; Lite Loaded",
        CurrentLevel: $("#user_level").text(),
        CurrentCity: /mw_city(\d)/.exec(document.getElementById("mw_city_wrapper").className)[1],
        Check: {
			AmAwake: false,
            AmRobbing: false,
			ItWas: false,
			JEI: 0,
			JSI: 0,
			tmpvaz: 0
		}, 
        LiteStorage: {
            EnergySelector: 1,
            StaminaSelector: 1,
            opponentMafiaMax: 501,
            opponentLevelMax: 65000,
            RobCity: 0,
            RobbingSlotSpeed: 0,
            RobSquads: 0,
            UseWhatFirst: 0,
            Spending: 0,
            BanditGamblerXP: false,
            BanditGamblerCSH: false,
            BanditElapsedTimerXP: 4,
            BanditElapsedTimerCash: 4,
            xp: true,
            BanditXPCheck: 0,
            csh: true,
            BanditCSHCheck: 0,
            jb: true,
            running: false,
			Autostart: false
        }
    };

    var jobsEN = new Array(
		{name: "New York"},
		{name: "Fight a Haitian Gang [1.60]", button: 17, city: 1, cost: 5, tab: 3, isOldCity: true, isUsingButton: false},
		{name: "Repel the Yakuza [1.81]", button: 29, city: 1, cost: 11, tab: 5, isOldCity: true, isUsingButton: false},
		{name: "Muscle in on a Triad Operation [1.95]", button: 65, city: 1, cost: 40, tab: 8, isOldCity: true, isUsingButton: false},
		{name: "Vegas"},
		{name: "Move The Take Out Of Town [1.96]", button: 40, city: 5, cost: 108, tab: 5, isOldCity: false, isUsingButton: false},
		{name: "Stash The Take [1.99]", button: 44, city: 5, cost: 226, tab: 5, isOldCity: false, isUsingButton: false},
		{name: "Rescue A Hotelier [1.97]", button: 50, city: 5, cost: 86, tab: 5, isOldCity: false, isUsingButton: false},
		{name: "Nab A High Tech Prototype [2.03]", button: 68, city: 5, cost: 158, tab: 7, isOldCity: false, isUsingButton: false},
		{name: "Dig Up Links To Halloran [2.07]", button: 73, city: 5, cost: 165, tab: 8, isOldCity: false, isUsingButton: false},
		{name: "Verify Halloran's Arrival [2.03]", button: 77, city: 5, cost: 165, tab: 8, isOldCity: false, isUsingButton: false},
		{name: "Dispose Of The Evidence [1.91]", button: 48, city: 5, cost: 64, tab: 5, isOldCity: false, isUsingButton: false},
		{name: "Brazil"},
		{name: "Run a Collection Plate Con [3.00]", button: 9, city: 7, cost: 1, tab: 1, isOldCity: false, isUsingButton: true},
		{name: "Give Chase to the Neo-Imperium [1.98]", button: 59, city: 7, cost: 756, tab: 5, isOldCity: false, isUsingButton: true},
		{name: "Bribe a Taubate Prison Worker [2.22]", button: 87, city: 7, cost: 648, tab: 8, isOldCity: false, isUsingButton: true},
		{name: "Assassinate the Neo-Imperium [2.19]", button: 95, city: 7, cost: 810, tab: 8, isOldCity: false, isUsingButton: true},
		{name: "Chicago"},
		{name: "Secure Hooch to Sell [2.17]", button: 10, city: 8, cost: 324, tab: 2, isOldCity: false, isUsingButton: true},
		{name: "Case Warehouses on North Side [2.14]", button: 12, city: 8, cost: 432, tab: 2, isOldCity: false, isUsingButton: true},
		{name: "Flee the Scene b4 the cops Arrive [1.96]", button: 48, city: 8, cost: 756, tab: 6, isOldCity: false, isUsingButton: true},
		{name: "London"},
		{name: "Approach The Police With Leads [2.05]", button: 19, city: 9, cost: 702, tab: 3, isOldCity: false, isUsingButton: true},
		{name: "Run The Racket [1.98]", button: 32, city: 9, cost: 1134, tab: 4, isOldCity: false, isUsingButton: true},
		{name: "Pay Off Your Debts [1.99]", button: 38, city: 9, cost: 1180, tab: 5, isOldCity: false, isUsingButton: true},
		{name: "Run Your Empire [2.24]", button: 39, city: 9, cost: 1080, tab: 5, isOldCity: false, isUsingButton: true},
		{name: "Ambush The Convoy [2.09]", button: 43, city: 9, cost: 1240, tab: 6, isOldCity: false, isUsingButton: true},
		{name: "Forge The Reports [2.18]", button: 45, city: 9, cost: 1350, tab: 6, isOldCity: false, isUsingButton: true},
		{name: "Chase Down Your Son's Kidnappers [2.23]", button: 52, city: 9, cost: 1188, tab: 7, isOldCity: false, isUsingButton: true},
		{name: "Sneak Into The Manor [2.19]", button: 53, city: 9, cost: 1026, tab: 7, isOldCity: false, isUsingButton: true},
		{name: "Retire To The Isle Of Wight [2.23]", button: 56, city: 9, cost: 1240, tab: 7, isOldCity: false, isUsingButton: true},
		{name: "Investigate The Puzzle Box [2.25]", button: 58, city: 9, cost: 972, tab: 8, isOldCity: false, isUsingButton: true},
		{name: "Steal The Puzzle Box [2.13]", button: 61, city: 9, cost: 1240, tab: 8, isOldCity: false, isUsingButton: true},
		{name: "Fight Off The Police [2.28]", button: 62, city: 9, cost: 1188, tab: 8, isOldCity: false, isUsingButton: true},
		{name: "Secret District \"When The Wild Strikes\""},
		{name: "Head For The Secret Amazonian Militant Base [2.03]",button: 891,city: 7,cost: 540,tab: 121,isOldCity: false,isUsingButton: true}, 
		{name: "Navigate Through The Rainforest To Find The Base [1.84]",button: 892,city: 7,cost: 594,tab: 121,isOldCity: false,isUsingButton: true}, 
		{name: "Infiltrate Secret Amazonian Militant Base [1.83]",button: 893,city: 7,cost: 756,tab: 121,isOldCity: false,isUsingButton: true}, 
		{name: "Sneak Into The Munitions Dump [2.05]",button: 894,city: 7,cost: 702,tab: 121,isOldCity: false,isUsingButton: true}, 
		{name: "Plant C4's In The Room [2.31]",button: 895,city: 7,cost: 648,tab: 121,isOldCity: false,isUsingButton: true}, 
		{name: "Get Caught By The Warlord And His Men [2.33]",button: 896,city: 7,cost: 594,tab: 121,isOldCity: false,isUsingButton: true}, 
		{name: "Turn The Warlord Into A Human Bomb [1.93]",button: 897,city: 7,cost: 864,tab: 121,isOldCity: false,isUsingButton: true}, 
		{name: "Demand That The Militia Buy Armaments Only From Your Company [2.19]",button: 898,city: 7,cost: 972,tab: 121,isOldCity: false,isUsingButton: true}, 
		{name: "Eliminate The Militia Upon Their Refusal [2.19]",button: 899,city: 7,cost: 1029,tab: 121,isOldCity: false,isUsingButton: true}			
		
/*Secret District "NightCap"*/
//		{name: "Secret District"},
//	{name: "Accept New Job Assigned To You [2.02]",button: 882,city: 8,cost: 486,tab: 120,isOldCity: false,isUsingButton: true}, 
//	{name: "Head To The Specified Location [2.03]",button: 883,city: 8,cost: 540,tab: 120,isOldCity: false,isUsingButton: true}, 
//	{name: "Look For Disloyal Associate [2.23]",button: 884,city: 8,cost: 594,tab: 120,isOldCity: false,isUsingButton: true}, 
//	{name: "Join Him To Avoid Any Suspicion [2.22]",button: 885,city: 8,cost: 648,tab: 120,isOldCity: false,isUsingButton: true}, 
//	{name: "Get Distracted [2.06]",button: 886,city: 8,cost: 756,tab: 120,isOldCity: false,isUsingButton: true}, 
//	{name: "Realize Your Associate Has Slipped Away [1.97]",button: 887,city: 8,cost: 702,tab: 120,isOldCity: false,isUsingButton: true}, 
//	{name: "Get Ready To Finish The Job[2.22]",button: 888,city: 8,cost: 648,tab: 120,isOldCity: false,isUsingButton: true}, 
//	{name: "Be Lured Into Backroom [2.33]",button: 889,city: 8,cost: 864,tab: 120,isOldCity: false,isUsingButton: true}, 
//	{name: "Become The Target Of Your Associates Assigned Job [2.19]",button: 890,city: 8,cost: 972,tab: 120,isOldCity: false,isUsingButton: true}
/*End Secret District "NightCap"*/		
/*Secret District "That's A Wrap"*/
//	{name: "Offer Your Movie Script To The Boss [2.37]",button: 873,city: 9,cost: 486,tab: 119,isOldCity: false,isUsingButton: true}, 
//	{name: "Procure Boss's Investment [2.23]",button: 874,city: 9,cost: 594,tab: 119,isOldCity: false,isUsingButton: true}, 
//	{name: "Start Production [2.22]",button: 875,city: 9,cost: 648,tab: 119,isOldCity: false,isUsingButton: true}, 
//	{name: "Refuse Boss's Demand To Change Your Script [2.06]",button: 876,city: 9,cost: 756,tab: 119,isOldCity: false,isUsingButton: true}, 
//	{name: "Plot Your Escape [2.23]",button: 877,city: 9,cost: 594,tab: 119,isOldCity: false,isUsingButton: true}, 
//	{name: "Knock Out The Boss With A Prop [2.05]",button: 878,city: 9,cost: 702,tab: 119,isOldCity: false,isUsingButton: true}, 
//	{name: "Take Him For What He's Worth [2.21]",button: 879,city: 9,cost: 756,tab: 119,isOldCity: false,isUsingButton: true}, 
//	{name: "Do Away With The Boss's Body [2.33]",button: 880,city: 9,cost: 864,tab: 119,isOldCity: false,isUsingButton: true}, 
//	{name: "Tweak The Script For A Better Ending [2.19]",button: 872,city: 9,cost: 972,tab: 119,isOldCity: false,isUsingButton: true}
/*End Secret District "That's A Wrap"*/			
		
/*	{name: "Make Deal With The Plantation Owner",button: 864,city: 7,cost: 540,tab: 118,isOldCity: false,isUsingButton: true}, 
	{name: "Start Seasoned Coffee Operation",button: 865,city: 7,cost: 594,tab: 118,isOldCity: false,isUsingButton: true}, 
	{name: "Muscle Out Your Competition",button: 866,city: 7,cost: 702,tab: 118,isOldCity: false,isUsingButton: true}, 
	{name: "Begin Smuggling The Goods",button: 867,city: 7,cost: 756,tab: 118,isOldCity: false,isUsingButton: true}, 
	{name: "Defend Truck From Kingpin Highwaymen",button: 868,city: 7,cost: 648,tab: 118,isOldCity: false,isUsingButton: true}, 
	{name: "Eliminate Highwaymen",button: 869,city: 7,cost: 756,tab: 118,isOldCity: false,isUsingButton: true}, 
{name: "Get Offer For Buyout From Caffeine Kingpin",button: 870,city: 7,cost: 648,tab: 118,isOldCity: false,isUsingButton: true}, 
{name: "Offer HIM A Buyout And Promise Protection",button: 871,city: 7,cost: 972,tab: 118,isOldCity: false,isUsingButton: true}, 
{name: "Force Him To Entrust His Property To You",button: 872,city: 7,cost: 1020,tab: 118,isOldCity: false,isUsingButton: true}
*///		{name: "Break Into The Longhorn Stockades [2.13]", button: 855, city: 8, cost: 486, tab: 117, isOldCity: false, isUsingButton: true},
//		{name: "Take Care Of Cattle Ranchers [2.13]", button: 856, city: 8, cost: 540, tab: 117, isOldCity: false, isUsingButton: true},
//		{name: "Create A Distraction To Enter The Slaughterhouse [2.23]", button: 857, city: 8, cost: 594, tab: 117, isOldCity: false, isUsingButton: true},
//		{name: "Clear The Slaughterhouse Of Any Bodies [2.33]", button: 862, city: 8, cost: 864, tab: 117, isOldCity: false, isUsingButton: true}
	);
	/*


		"28": new JobEnergySelector(29, 540, 118, 7, "Make Deal With The Plantation Owner [2.03]", 864, "purple", true, false),
		"29": new JobEnergySelector(30, 594, 118, 7, "Start Seasoned Coffee Operation [2.23]", 865, "purple", true, false),
		"30": new JobEnergySelector(31, 702, 118, 7, "Muscle Out Your Competition [1.90]", 866, "purple", true, false),
		"31": new JobEnergySelector(32, 756, 118, 7, "Begin Smuggling The Goods [1.90]", 867, "purple", true, false),
		"32": new JobEnergySelector(33, 648, 118, 7, "Defend Truck From Kingpin Highwaymen [2.22]", 867, "purple", true, false),
		"33": new JobEnergySelector(34, 756, 118, 7, "Eliminate Highwaymen [1.73]", 869, "purple", true, false),
		"34": new JobEnergySelector(35, 648, 118, 7, "Get Offer For Buyout From Caffeine Kingpin [2.31]", 870, "purple", true, false),
		"35": new JobEnergySelector(36, 972, 118, 7, "Offer HIM A Buyout And Promise Protection [2.19]", 871, "purple", true, false),
		"36": new JobEnergySelector(1, 1020, 118, 7, "Force Him To Entrust His Property To You [2.19]", 872, "purple", true, false)
	*/
    var jobsSta = new Array(
		{name: "Vegas"},
		{name: "Question Some Meth Heads [2.2250]", button: 72, city: 5, cost: 120, tab: 8, isFobbing: true, isRobbing: false},
		{name: "Eliminate A Hill Supplier [2.2578]", button: 54, city: 5, cost: 128, tab: 6, isFobbing: true, isRobbing: false},
		{name: "Clean Out A Biker Bar [2.2578]", button: 46, city: 5, cost: 44, tab: 5, isFobbing: true, isRobbing: false},
		{name: "Other"},
		{name: "Robbing", button: "ExpertMapController.selectNode(44); MapController.panelButtonDoJob(44)", city: 5, cost: 50, tab: 5, isFobbing: false, isRobbing: true}
	);
	
    var ric = new Array('1', '5', '7', '8', '9');
    var ris = new Array('187', '250', '500', '750', '1000', '2000');
    var RS = new Array('false', 'true');
    var SpendEnergyOrStamina = new Array('energy', 'stamina', 'toe2toe', 'jnrg', 'jstam');
    var WhichSkill = new Array('none','attack','defense','max_energy','max_stamina');
    var fn;
    var blitz;
    var bhk;
    var bhhk;
	var FUUUUUUU = 0;
	var http = 'http://';
	if (/https/.test(document.location)) {
		http = 'https://';
	}
	var preurl = http+'facebook.mafiawars.zynga.com/mwfb/remote/html_server.php?';

    function create_div() {
		readSettings();
        var content = document.getElementById('final_wrapper');
        var dronehtml = '<div id="toolbar_content" class="clearfix empire_module_title" style="height: 30px;width:750px;">Drone.&#12324; Lite<a id="droneSettings" style="position:relative; left:10px; height: 30px;" class="sexy_button_new short black"><span class="sexy_health_new"><span><img src="http://mwfb.static.zgncdn.com/mwfb/graphics/v3/icon_hammer_wrench.png"></span></span></a><a id="onoff" style="position:relative; left:15px;height: 30px;" class="sexy_button_new short white"><span><span>Start</span></span></a>&nbsp;&nbsp;&nbsp;<span style="position:relative;left:15px;width:300px;font-size:18px;color:grey" id="droneStatus"> ' + DroneLite.Status + ' </span><a id="RemoveIt" style="top: 11px; right: 15px;" title="Click me to remove this bar" class="pop_close"></a></div>';
        if (document.getElementById('gxDivLite')) {
            document.getElementById('gxDivLite').innerHTML = dronehtml;
            document.getElementById("onoff").onclick = startdrone;
            document.getElementById('droneSettings').addEventListener("click", function(){Settings()}, false);
			document.getElementById('RemoveIt').addEventListener("click", function(){RemoveMe()}, false);
			document.getElementById('onoff').addEventListener("click", function(){startdrone()}, false);
            if (DroneLite.LiteStorage.running) {
                document.getElementById("onoff").setAttribute("class", "sexy_button_new short green");
                document.getElementById("onoff").innerHTML = "<span><span>Running</span></span>"
            }
        } else {
            var gxDivLite = document.createElement("div");
            gxDivLite.id = 'gxDivLite';
            content.insertBefore(gxDivLite, content.firstChild);
            document.getElementById('gxDivLite').innerHTML = dronehtml;
            document.getElementById('droneSettings').addEventListener("click", function(){Settings()}, false);
			document.getElementById('RemoveIt').addEventListener("click", function(){RemoveMe()}, false);
			document.getElementById('onoff').addEventListener("click", function(){startdrone()}, false);
        }
    }

    function RemoveMe() {
		DroneLite.LiteStorage.running = false;
		try{
			document.getElementById('popup_fodder').removeChild(document.getElementById('DroneLiteSettings'));
		}catch(err){}
        $('#gxDivLite').remove();
    }
	
    function Settings() {
		if (DroneLite.LiteStorage.running) {
			DroneLite.Check.ItWas = true;
            DroneLite.LiteStorage.running = false;
			clearTimeout(DroneLite.Check.JEI);
			DroneLite.Status = "Drone Settings Change, Paused";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            document.getElementById("onoff").setAttribute("class", "sexy_button_new short gold");
            document.getElementById("onoff").innerHTML = "<span><span>Paused</span></span>"
		}
        content = '&nbsp;Energy:<br>&nbsp;<select id="DLES" onChange="EnergySelector(this.selectedIndex)">';
        for (i = 0; i < jobsEN.length; i++) {
            content += '<option value="' + i + '">' + jobsEN[i].name + "</option>"
        }
        content += '</select><br><br>&nbsp;Stamina:&nbsp;<br>&nbsp;<select id="DLSS" onChange="StaminaSelector(this.selectedIndex)">';
        for (i = 0; i < jobsSta.length; i++) {
            content += '<option value="' + i + '">' + jobsSta[i].name + "</option>"
        }
        content += '</select><br style="line-height: 25px;"><span id="FobRow" style="display:none">' + '&nbsp;Mafia Size&nbsp;<input id="DLVFMS" type="integer" value="501" style="resize:none;width:25px;">&nbsp;Mafia Level&nbsp;<input id="DLVFML" type="integer" value="65000" style="resize:none;width:40px;"><br>' + '</span><span id="RobRow" style="display:none">' + '&nbsp;Rob in&nbsp;<select id="DLRC"><option value="0">New York</option><option value="1">Las Vegas</option><option value="2">Brazil</option><option value="3">Chicago</option><option value="4">London</option></select><br style="line-height: 25px;">&nbsp;Rob Individual Speed&nbsp;<select id="DLRIS"><option value="0">0.15</option><option value="1">0.25</option><option value="2">0.50</option><option value="3">0.75</option><option value="4">1.00</option><option value="5">2.00</option></select><br style="line-height: 25px;">&nbsp;Use Robsquads&nbsp;<select id="DLRS"><option value="0">No!</option><option value="1">Yes!</option></select><br>' + '</span><br>&nbsp;Spend:&nbsp;<select id="DLSpendWhich"><option value="0">Energy First</option><option value="1">Stamina First</option><option value="2">Toe to Toe</option><option value="3">Only Energy</option><option value="4">Only Stamina</option></select><br><br>&nbsp;Apply Skillpoints:&nbsp;<select id="DLSpendSkills"><option value="0">No!</option><option value="1">Attack</option><option value="2">Defense</option><option value="3">Energy</option><option value="4">Stamina</option></select><br><br>&nbsp;Bandits:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="DLkillxp">&nbsp;Kill XP Bandit&nbsp;<select id="XPBanO" onChange="BanditXPCheck(this.selectedIndex)"><option value="0" href="#" id="xpcheck0">Don\'t Gamble</option><option value="1" href="#" id="xpcheck1">Kill with 1 minute to go</option><option value="2" href="#" id="xpcheck2">Kill with 2 minutes to go</option><option value="3" href="#" id="xpcheck3">Kill with 3 minutes to go</option>' + '</select><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="DLkillcsh">&nbsp;Kill Cash Bandit&nbsp;<select id="CSHBanO" onChange="BanditCSHCheck(this.selectedIndex)"><option value="0" href="#" id="cshcheck0">Don\'t Gamble</option><option value="1" href="#" id="cshcheck1">Kill with 1 minute to go</option><option value="2" href="#" id="cshcheck2">Kill with 2 minutes to go</option><option value="3" href="#" id="cshcheck3">Kill with 3 minutes to go</option></select><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="DLkilljb">&nbsp;Kill Job Bandit<br><br>&nbsp;Autostart&nbsp;<input type="checkbox" id="AutorunMe" ><span class="more_in">(Autoruns when MW starts)</span><center><a id="savedcfg" href="#" class="sexy_button_new short green"><span><span>Close</span></span></a></center>&nbsp;&nbsp';
        myPop("DroneLiteSettings", content);
        document.getElementById("DLES").options[0].disabled = "disabled";
        document.getElementById("DLES").options[4].disabled = "disabled";
        document.getElementById("DLES").options[12].disabled = "disabled";
        document.getElementById("DLES").options[17].disabled = "disabled";
        document.getElementById("DLES").options[21].disabled = "disabled";
        document.getElementById("DLES").options[34].disabled = "disabled";
        document.getElementById("DLSS").options[0].disabled = "disabled";
        document.getElementById("DLSS").options[4].disabled = "disabled";
        $('#DLES option:eq(' + DroneLite.LiteStorage.EnergySelector + ')').prop('selected', true)
			EnergySelector(DroneLite.LiteStorage.EnergySelector);
        $('#DLSS option:eq(' + DroneLite.LiteStorage.StaminaSelector + ')').prop('selected', true)
			StaminaSelector(DroneLite.LiteStorage.StaminaSelector);
        document.getElementById("DLVFMS").value = DroneLite.LiteStorage.opponentMafiaMax;
        document.getElementById("DLVFML").value = DroneLite.LiteStorage.opponentLevelMax;
        document.getElementById("DLRC").selectedIndex = DroneLite.LiteStorage.RobCity;
        document.getElementById("DLRIS").selectedIndex = DroneLite.LiteStorage.RobbingSlotSpeed;
        document.getElementById("DLRS").selectedIndex = DroneLite.LiteStorage.RobSquads;
        document.getElementById("DLSpendWhich").selectedIndex = DroneLite.LiteStorage.UseWhatFirst;
        document.getElementById("DLSpendSkills").selectedIndex = DroneLite.LiteStorage.Spending;
        if (DroneLite.LiteStorage.xp) {
            document.getElementById("DLkillxp").checked = true;
        }
        $('#XPBanO option:eq(' + DroneLite.LiteStorage.BanditXPCheck + ')').prop('selected', true)
			BanditXPCheck(DroneLite.LiteStorage.BanditXPCheck);
        if (DroneLite.LiteStorage.csh) {
            document.getElementById("DLkillcsh").checked = true;
        }
        $('#CSHBanO option:eq(' + DroneLite.LiteStorage.BanditCSHCheck + ')').prop('selected', true)
			BanditCSHCheck(DroneLite.LiteStorage.BanditCSHCheck);
        if (DroneLite.LiteStorage.jb) {
            document.getElementById("DLkilljb").checked = true;
        }
			if (DroneLite.LiteStorage.xp) {
                document.getElementById("DLkillxp").checked = true;
            }
			if (DroneLite.LiteStorage.csh) {
                document.getElementById("DLkillcsh").checked = true;
            }
			if (DroneLite.LiteStorage.jb) {
                document.getElementById("DLkilljb").checked = true;
            }
			if (DroneLite.LiteStorage.Autostart) {
                document.getElementById("AutorunMe").checked = true;
            }
			
        $('#savedcfg').click(function () {
            closeZpopup();
        });
    }
	
    function closeZpopup() {
		if (DroneLite.Check.ItWas) {
			SaveDLS();
			DroneLite.Check.ItWas = false;
            DroneLite.LiteStorage.running = true;
			checkStamEnergy();
			document.getElementById('popup_fodder').removeChild(document.getElementById('DroneLiteSettings'));
			return;
		}else{
		SaveDLS();
			document.getElementById('popup_fodder').removeChild(document.getElementById('DroneLiteSettings'));
			return;
		}
    }

    function ResetR() {
        DroneLite.Check.AmAwake = false;
        DroneLite.Check.AmRobbing = false;
        return;
    }


    EnergySelector = function (n) {
        if (DroneLite.LiteStorage.EnergySelector != n) {
            DroneLite.LiteStorage.EnergySelector = n;
			writeSettings();
        }
        switch (parseInt(n)) {
        case 0:
            DroneLite.Check.tmpvaz = 0;
            break;
        case 1:
            DroneLite.Check.tmpvaz = 1;
            break;
        case 2:
            DroneLite.Check.tmpvaz = 2;
            break;
        case 3:
            DroneLite.Check.tmpvaz = 3;
            break;
        case 4:
            DroneLite.Check.tmpvaz = 4;
            break;
        case 5:
            DroneLite.Check.tmpvaz = 5;
            break;
        case 6:
            DroneLite.Check.tmpvaz = 6;
            break;
        case 7:
            DroneLite.Check.tmpvaz = 7;
            break;
        case 8:
            DroneLite.Check.tmpvaz = 8;
            break;
        case 9:
            DroneLite.Check.tmpvaz = 9;
            break;
        case 10:
            DroneLite.Check.tmpvaz = 10;
            break;
        case 11:
            DroneLite.Check.tmpvaz = 11;
            break;
        case 12:
            DroneLite.Check.tmpvaz = 12;
            break;
        case 13:
            DroneLite.Check.tmpvaz = 13;
            break;
        case 14:
            DroneLite.Check.tmpvaz = 14;
            break;
        case 15:
            DroneLite.Check.tmpvaz = 15;
            break;
        case 16:
            DroneLite.Check.tmpvaz = 16;
            break;
        case 17:
            DroneLite.Check.tmpvaz = 17;
            break;
        case 18:
            DroneLite.Check.tmpvaz = 18;
            break;
        case 19:
            DroneLite.Check.tmpvaz = 19;
            break;
        case 20:
            DroneLite.Check.tmpvaz = 20;
            break;
        case 21:
            DroneLite.Check.tmpvaz = 21;
            break;
        case 22:
            DroneLite.Check.tmpvaz = 22;
            break;
        case 23:
            DroneLite.Check.tmpvaz = 23;
            break;
        case 24:
            DroneLite.Check.tmpvaz = 24;
            break;
        case 25:
            DroneLite.Check.tmpvaz = 25;
            break;
        case 26:
            DroneLite.Check.tmpvaz = 26;
            break;
        case 27:
            DroneLite.Check.tmpvaz = 27;
            break;
        case 28:
            DroneLite.Check.tmpvaz = 28;
            break;
        case 29:
            DroneLite.Check.tmpvaz = 29;
            break;
        case 30:
            DroneLite.Check.tmpvaz = 30;
            break;
        case 31:
            DroneLite.Check.tmpvaz = 31;
            break;
        case 32:
            DroneLite.Check.tmpvaz = 32;
            break;
        case 33:
            DroneLite.Check.tmpvaz = 33;
            break;
        case 34:
            DroneLite.Check.tmpvaz = 34;
            break;
        case 35:
            DroneLite.Check.tmpvaz = 35;
            break;
        case 36:
            DroneLite.Check.tmpvaz = 36;
            break;
        case 37:
            DroneLite.Check.tmpvaz = 37;
            break;
        }
    }
	
    StaminaSelector = function (n) {
        if (DroneLite.LiteStorage.StaminaSelector != n) {
            DroneLite.LiteStorage.StaminaSelector = n;
			writeSettings();
        }
        switch (parseInt(n)) {
        case 0:
            $('#FobRow').hide();
            $('#RobRow').hide();
            break;
        case 1:
            $('#FobRow').show();
            $('#RobRow').hide();
            break;
        case 2:
            $('#FobRow').show();
            $('#RobRow').hide();
            break;
        case 3:
            $('#FobRow').show();
            $('#RobRow').hide();
            break;
        case 4:
            $('#FobRow').hide();
            $('#RobRow').hide();
            break;
        case 5:
            $('#FobRow').hide();
            $('#RobRow').show();
            break;
        }
    }

    BanditXPCheck = function (n) {
        if (DroneLite.LiteStorage.BanditXPCheck != n) {
            DroneLite.LiteStorage.BanditXPCheck = n;
			writeSettings();
        }
        switch (parseInt(n)) {
        case 0:
            DroneLite.LiteStorage.BanditGamblerXP = false;
            DroneLite.LiteStorage.BanditElapsedTimerXP = 4;
            break;
        case 1:
            DroneLite.LiteStorage.BanditGamblerXP = true;
            DroneLite.LiteStorage.BanditElapsedTimerXP = 1;
            break;
        case 2:
            DroneLite.LiteStorage.BanditGamblerXP = true;
            DroneLite.LiteStorage.BanditElapsedTimerXP = 2;
            break;
        case 3:
            DroneLite.LiteStorage.BanditGamblerXP = true;
            DroneLite.LiteStorage.BanditElapsedTimerXP = 3;
            break;
        }
    }

    BanditCSHCheck = function (n) {
        if (DroneLite.LiteStorage.BanditCSHCheck != n) {
            DroneLite.LiteStorage.BanditCSHCheck = n;
			writeSettings();
        }
        switch (parseInt(n)) {
        case 0:
            DroneLite.LiteStorage.BanditGamblerCSH = false;
            DroneLite.LiteStorage.BanditElapsedTimerCash = 4;
            break;
        case 1:
            DroneLite.LiteStorage.BanditGamblerCSH = true;
            DroneLite.LiteStorage.BanditElapsedTimerCash = 1;
            break;
        case 2:
            DroneLite.LiteStorage.BanditGamblerCSH = true;
            DroneLite.LiteStorage.BanditElapsedTimerCash = 2;
            break;
        case 3:
            DroneLite.LiteStorage.BanditGamblerCSH = true;
            DroneLite.LiteStorage.BanditElapsedTimerCash = 3;
            break;
        }
    }

    function SaveDLS() {

        DroneLite.LiteStorage.opponentMafiaMax = parseInt(document.getElementById("DLVFMS").value);
        DroneLite.LiteStorage.opponentLevelMax = parseInt(document.getElementById("DLVFML").value);
        DroneLite.LiteStorage.RobCity = document.getElementById("DLRC").selectedIndex;
        DroneLite.LiteStorage.RobbingSlotSpeed = document.getElementById("DLRIS").selectedIndex;
        DroneLite.LiteStorage.RobSquads = document.getElementById("DLRS").selectedIndex;
        DroneLite.LiteStorage.UseWhatFirst = document.getElementById("DLSpendWhich").selectedIndex;
        DroneLite.LiteStorage.Spending = document.getElementById("DLSpendSkills").selectedIndex;
        if (document.getElementById('DLkillxp').checked) {
            DroneLite.LiteStorage.xp = true;
        } else {
            DroneLite.LiteStorage.xp = false;
        }
        if (document.getElementById('DLkillcsh').checked) {
            DroneLite.LiteStorage.csh = true;
        } else {
            DroneLite.LiteStorage.csh = false;
        }
        if (document.getElementById('DLkilljb').checked) {
            DroneLite.LiteStorage.jb = true;
        } else {
            DroneLite.LiteStorage.jb = false;
        }
		if (document.getElementById("AutorunMe").checked) {
            DroneLite.LiteStorage.Autostart = true;
        }else {
            DroneLite.LiteStorage.Autostart = false;
        }

		writeSettings();
    }
	
    function myPop(popupId, content, width, shouldClose) {
        var popup = '<div id="' + popupId + '" class="pop_box " style="position:absolute;top:100px;left:200px;display: block;width:380px;z-index:999999;"><a id="RemoveIti" title="Close Settings" class="pop_close"></a><div style="z-index:99999" class="mini_EP_info_pop">' + '<span style="position:relative;top:5px"><h3 style="text-align:center;">Drone.&#12324; Lite</h3><hr><span style="position:relative;top:5px">' + content + "</span></center></div></div>";
        document.getElementById("popup_fodder").innerHTML += popup;
		document.getElementById('RemoveIti').addEventListener("click", function(){closeZpopup()}, false);
        if (shouldClose) {
            setTimeout(function () {
                document.getElementById("popup_fodder").removeChild(document.getElementById(popupId))
            }, shouldClose)
        }
    }

    function startdrone() {
        if (DroneLite.LiteStorage.running) {
            DroneLite.LiteStorage.running = false;
            DroneLite.Status = "Drone Stopped";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            document.getElementById("onoff").setAttribute("class", "sexy_button_new short red");
            document.getElementById("onoff").innerHTML = "<span><span>Stopped</span></span>"
        } else {
            DroneLite.LiteStorage.running = true;
            DroneLite.CurrentEnergyJob = DroneLite.LiteStorage.EnergySelector;
            DroneLite.CurrentStaminaJob = DroneLite.LiteStorage.StaminaSelector;
            document.getElementById("onoff").setAttribute("class", "sexy_button_new short green");
            document.getElementById("onoff").innerHTML = "<span><span>Running</span></span>";
            checkStamEnergy();
        }
    }
	
	function checkStamEnergy() {
		if (!DroneLite.LiteStorage.running) {
            return;
        }
        DroneLite.Energy = parseInt(document.getElementById("user_energy").innerHTML);
        DroneLite.Stamina = parseInt(document.getElementById("user_stamina").innerHTML);
		DroneLite.CurrentEnergyJob = DroneLite.LiteStorage.EnergySelector;
        DroneLite.CurrentStaminaJob = DroneLite.LiteStorage.StaminaSelector;
	//	alert(''+SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst]+'\n'+jobsEN[DroneLite.LiteStorage.EnergySelector].cost+'\n'+jobsSta[DroneLite.LiteStorage.StaminaSelector].cost+'');
	//	return;
        document.getElementById("onoff").setAttribute("class", "sexy_button_new short green");
        document.getElementById("onoff").innerHTML = "<span><span>Running</span></span>";
		DroneLite.Status = "Checking Stam & Energy";
        document.getElementById("droneStatus").innerHTML = DroneLite.Status;
		
        if (DroneLite.Stamina < jobsSta[DroneLite.LiteStorage.StaminaSelector].cost && DroneLite.Energy < jobsEN[DroneLite.LiteStorage.EnergySelector].cost) {
            DroneLite.Status = "No Resources, Re-Checking in 5 minutes...";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            setTimeout(checkStamEnergy, 300000)
            return;
        }
        if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'stamina') {
            setTimeout(StaminaTraveler, 2000);
            return;
        }
		if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'energy') {
            setTimeout(EnergyTraveler, 2000);
            return;
        } 
		if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'jnrg') {
            setTimeout(EnergyTraveler, 2000);
            return;
        } 
		if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'jstam') {
            setTimeout(StaminaTraveler, 2000);
            return;
        } 
		if (DroneLite.Energy < jobsEN[DroneLite.LiteStorage.EnergySelector].cost) {
            setTimeout(StaminaTraveler, 2000);
            return;
        } else {
            setTimeout(EnergyTraveler, 2000);
            return;
        }
	}

    function spendSkills() {
        if (!DroneLite.LiteStorage.running) {
            return;
        }
        var IhaZskills = parseInt($('#user_skill').text());
        if (IhaZskills >= 5 && DroneLite.LiteStorage.Spending != 0) {
            do_ajax('', 'remote/html_server.php?xw_controller=stats&xw_action=upgrade&xw_city=5&upgrade_key=' + WhichSkill[DroneLite.LiteStorage.Spending] + '&upgrade_amt=5&no_load=1&source=level_up_popup');
            return;
        }
    }

    function EnergyTraveler() {
		if (!DroneLite.LiteStorage.running) {
            return;
        }
        DroneLite.Status = "Traveling to Jobs...";
        document.getElementById("droneStatus").innerHTML = DroneLite.Status;
        do_ajax("inner_page", "remote/html_server.php?xw_controller=travel&xw_action=travel&xw_city=7&from=job&zone=1&destination=" + jobsEN[DroneLite.CurrentEnergyJob].city + "&tab=" + jobsEN[DroneLite.CurrentEnergyJob].tab, 1, 1, 0, 0);
		setTimeout(ResetR, 3450);
        setTimeout(EnergyOp, 3500);
        return;
    }

    function StaminaTraveler() {
		if (!DroneLite.LiteStorage.running) {
            return;
        }
        DroneLite.Status = "Traveling to Stamina Destination...";
        document.getElementById("droneStatus").innerHTML = DroneLite.Status;
        if (jobsSta[DroneLite.LiteStorage.StaminaSelector].isFobbing) {
            do_ajax("mainDiv", "remote/html_server.php?xw_controller=travel&xw_action=travel&xw_city=7&from=job&zone=1&destination=" + jobsSta[DroneLite.CurrentStaminaJob].city + "&tab=" + jobsSta[DroneLite.CurrentStaminaJob].tab + "");
        }
        if (jobsSta[DroneLite.LiteStorage.StaminaSelector].isRobbing) {
            do_ajax("mainDiv", "remote/html_server.php?xw_controller=travel&xw_action=travel&xw_city=7&destination=" + ric[DroneLite.LiteStorage.RobCity] + "&from=robbing&zone=1&nextParams=&menu=travel");
        }
		setTimeout(ResetR, 3450);
        setTimeout(StaminaOp, 3500);
        return;
    }

    function StaminaOp() {
        DroneLite.Energy = parseInt(document.getElementById("user_energy").innerHTML);
        DroneLite.Stamina = parseInt(document.getElementById("user_stamina").innerHTML);
        DroneLite.CurrentCity = getCurrCity();
        if (!DroneLite.LiteStorage.running) {
            return;
        }
		spendSkills();
		if(DroneLite.Stamina < jobsSta[DroneLite.LiteStorage.StaminaSelector].cost && DroneLite.Energy < jobsEN[DroneLite.LiteStorage.EnergySelector].cost){
			checkStamEnergy();
			return;
		}
        if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'jstam' && DroneLite.Stamina < jobsSta[DroneLite.LiteStorage.StaminaSelector].cost) {
			DroneLite.LiteStorage.running = false;
            DroneLite.Status = "Just Stamina haz been spent";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            document.getElementById("onoff").setAttribute("class", "sexy_button_new short red");
            document.getElementById("onoff").innerHTML = "<span><span>Stopped</span></span>"
            return;
		}
        if (DroneLite.Stamina < jobsSta[DroneLite.LiteStorage.StaminaSelector].cost){
			EnergyTraveler();
            return;
        }
		if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'jnrg' && DroneLite.Energy > jobsEN[DroneLite.LiteStorage.EnergySelector].cost) {
			EnergyTraveler();
            return;
		}
		if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'energy' && DroneLite.Energy > jobsEN[DroneLite.LiteStorage.EnergySelector].cost) {
			EnergyTraveler();
            return;
		}else {
            DoStaminaJob();
            killPopup();
            return;
        }
    }

    function DoStaminaJob() {
		if (!DroneLite.LiteStorage.running) {
            return;
        }
        if (jobsSta[DroneLite.LiteStorage.StaminaSelector].isFobbing) {
            if (DroneLite.CurrentCity != 5) {
                setTimeout(StaminaTraveler, 3500);
                return;
            }
			if(DroneLite.Check.AmAwake){
				return;
			}
			DroneLite.Check.AmAwake = true;
            DroneLite.Status = "Doing Fight Jobs";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            if (bhhk == 1) {
                var Wording = $('#side_container').text();
                var FindItNow = /You won the fight!/g;
                var Annnnd = FindItNow.test(Wording);
                if (Annnnd == true) {
                    fn();
					setTimeout(ResetR, 450);
                    setTimeout(StaminaOp, 500);
                    return;
                } else {
                    bhhk = 0;
                    bhk = 0;
                }
            }
            if (bhk == 1) {
                fn();
                bhhk = 1;
				setTimeout(ResetR, 2900);
                setTimeout(StaminaOp, 3000);
                return;
            } else {
                bhk = 0;
            }
            if (blitz == 1) {
                var Wording = $('#side_container').text();
                var FindItNow = /You won the fight!/g;
                var Annnnd = FindItNow.test(Wording);
                //					alert(Annnnd);
                if (Annnnd == true) {
                    fn();
                    bhk = 1;
					setTimeout(ResetR, 950);
                    setTimeout(StaminaOp, 1000);
                    return;
                } else {
                    blitz = 0;
                }
            }
            targetElts = $x('.//a[contains(@onclick,"doFightJob(' + jobsSta[DroneLite.CurrentStaminaJob].button + '")]');
            numTargets = targetElts.length;
            if (numTargets) {
                var OppName, OppSize, OppLevel;
                var smallestMafia = DroneLite.LiteStorage.opponentMafiaMax;
                var lowestLevel = DroneLite.LiteStorage.opponentLevelMax;
                var foundOpp = false;
                for (i = 0; i < numTargets; i++) {
                    targetParent = targetElts[i].parentNode.parentNode;
                    parentNoTags = targetParent.innerHTML.untag();
                    if (parentNoTags.match(/(.+?)\s+(.+?)\s+(.+?)\s+Fight/i)) {
                        OppName = RegExp.$1;
                        OppSize = parseInt(RegExp.$2);
                        OppLevel = parseInt(RegExp.$3);
                    } else {
                        OppNameElt = xpathFirst('.//dt[@class="name"]//span[@class="player_data"]', targetParent);
                        if (OppNameElt) OppName = OppNameElt.innerHTML.untag();
                        OppSizeElt = xpathFirst('.//dd[@class="group_size"]//span[@class="player_data"]', targetParent);
                        if (OppSizeElt) OppSize = parseInt(OppSizeElt.innerHTML.untag());
                        OppLevelElt = xpathFirst('.//dd[@class="level"]//span[@class="player_data"]', targetParent);
                        if (OppLevelElt) OppLevel = parseInt(OppLevelElt.innerHTML.untag());
                    }
                    if ((OppSize != 0 && OppLevel != 0) && (OppSize < smallestMafia || (OppSize == smallestMafia && OppLevel < lowestLevel))) {
                        OppTarget = targetElts[i];
                        OppTargetParent = targetParent;
                        smallestMafia = OppSize;
                        lowestLevel = OppLevel;
                        foundOpp = true;
                    } else {}
                }
                if (foundOpp) {
                    /* Thanks to Midian, Lets inject the blitz hack */
                    fn = new Function(OppTarget.getAttribute('onclick'));
                    fn();
                    blitz = 1;
                    /* Midian */
					setTimeout(ResetR, 2450);
                    setTimeout(StaminaOp, 2500);
                    return;
                } else {
                    do_ajax('mainDiv', 'remote/html_server.php?xw_controller=travel&xw_action=travel&xw_city=7&from=job&zone=1&destination=' + jobsSta[DroneLite.CurrentStaminaJob].city + '&tab=' + jobsSta[DroneLite.CurrentStaminaJob].tab + '');
					setTimeout(ResetR, 5900);
                    setTimeout(StaminaOp, 6000);
                    return;
                }
            }
        }
        if (jobsSta[DroneLite.LiteStorage.StaminaSelector].isRobbing) {
            if (DroneLite.Check.AmRobbing) {
                return;
            }
            DroneLite.Check.AmRobbing = true;
            var tabtest = document.evaluate('//li[contains(@class, "tab_on")]//a[contains(., "Robbing")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength > 0;
            if (tabtest == 0) {
                setTimeout(ResetR, 3450);
                setTimeout(StaminaTraveler, 3500);
                return;
            }
            DroneLite.Status = "Doing Robbing";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            var spreecount = parseInt($('#call_sprees_left').text());
            if (spreecount > 0 && RS[DroneLite.LiteStorage.RobSquads] == 'true') {
                document.getElementById("oneClickRobAll").click();
                setTimeout(ResetR, 6450);
                setTimeout(RefreshMe, 6500);
                return;
            }
            var slotcount = 8;
            for (var i = 8; i >= 0; i--) {
                setTimeout("do_ajax('','remote/html_server.php?xw_controller=robbing&xw_action=rob&xw_city=1&slot=" + slotcount + "', 1, 0, RobbingController.preRob(2), RobbingController.rob);", i * ris[DroneLite.LiteStorage.RobbingSlotSpeed]);
                slotcount--;
            }
            setTimeout(ResetR, 7200);
            setTimeout(RefreshMe, 7250);
            return;
        }
    }

    function RefreshMe() {
		if (!DroneLite.LiteStorage.running) {
            return;
        }
        try {
            var IsEveryoneDeadYet = document.evaluate("//a[@id=\"rob_refresh_cost\"]//span//span[contains(string(),'Refresh: 0')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
            if (IsEveryoneDeadYet.snapshotLength >= 1) {
                killPopup();
                do_ajax('mainDiv', 'remote/html_server.php?xw_controller=robbing&xw_action=refresh');
                setTimeout(StaminaOp, 6500);
                DroneLite.Status = "Refreshing Board";
                document.getElementById("droneStatus").innerHTML = DroneLite.Status;
                return;
            } else {
                StaminaOp();
                return;
            }
        } catch (err) {}
    }

    function xpathFirst(p, c) {
        return document.evaluate(p, c || document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
    }

    function $x(p, c) {
        var i, r = [],
            x = document.evaluate(p, c || document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
        while ((i = x.iterateNext())) r.push(i);
        return r;
    }

    String.prototype.untag = function () {
        return this.replace(/<[^>]*>/g, '');
    };

	function EnergyOp() {
	    DroneLite.Energy = parseInt(document.getElementById("user_energy").innerHTML);
	    DroneLite.Stamina = parseInt(document.getElementById("user_stamina").innerHTML);
	    DroneLite.CurrentCity = getCurrCity();
	    if (!DroneLite.LiteStorage.running) {
	        return;
	    }
	    try {
	        var nqued = $('#btn_queue').text();
	        var hazbeenposted = $('#btn_crew_recruit').text();
	        var anqued = nqued.substring(2);
	        var tellmeNow = /Ask/g;
	        var Annnnd = tellmeNow.test(hazbeenposted);
	    } catch (err) {}
		spendSkills();
	    if (FUUUUUUU == 1 && DroneLite.Energy < jobsEN[DroneLite.LiteStorage.EnergySelector].cost) {
	        FUBUTTON = document.getElementsByClassName("sexy_button_new sexy_button_new short red impulse_buy")[0];
	        if (!FUBUTTON) {
	            FUUUUUUU = 0;
	            setTimeout(EnergyTraveler, 3000);
	            return;
	        }
	        DroneLite.Status = "Attempting to kill bandit..";
	        document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	        FUBUTTON.click();
	        FUUUUUUU = 0;
	        setTimeout(EnergyTraveler, 6000);
	        return;
	    }
		if(DroneLite.Stamina < jobsSta[DroneLite.LiteStorage.StaminaSelector].cost && DroneLite.Energy < jobsEN[DroneLite.LiteStorage.EnergySelector].cost){
			checkStamEnergy();
			return;
		}
		if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'jnrg' && DroneLite.Energy < jobsEN[DroneLite.LiteStorage.EnergySelector].cost) {
			DroneLite.LiteStorage.running = false;
            DroneLite.Status = "Just Energy haz been spent";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            document.getElementById("onoff").setAttribute("class", "sexy_button_new short red");
            document.getElementById("onoff").innerHTML = "<span><span>Stopped</span></span>"
            return;
		}
		if (DroneLite.Energy < jobsEN[DroneLite.LiteStorage.EnergySelector].cost){
			StaminaTraveler();
            return;
		}
		if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'stamina' && DroneLite.Stamina > jobsSta[DroneLite.LiteStorage.StaminaSelector].cost) {
			StaminaTraveler();
            return;
		}
		if (SpendEnergyOrStamina[DroneLite.LiteStorage.UseWhatFirst] == 'jstam' && DroneLite.Stamina > jobsSta[DroneLite.LiteStorage.StaminaSelector].cost) {
			StaminaTraveler();
            return;
		} else {
	        if (document.getElementsByClassName("bandit-eliminate-btn").length > 0) {
	            var a = document.getElementsByClassName("sexy_button_new sexy_button_new short red impulse_buy")[0];
	            if (!a) {
	                setTimeout(EnergyTraveler, 3000);
	                return;
	            }
	            var sillyBTimer = $(".bandit-timer").text();
	            var texBandit = parseInt(sillyBTimer);
	            var hazbeenposted = $('#btn_crew_recruit').text();
	            var tellmeNow = /Posted/g;
	            var Annnnd = tellmeNow.test(hazbeenposted);
	            if (anqued == 0 && Annnnd == false) {
	                DroneLite.Status = "Attempting to post for crew..";
	                document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	                var qclickMe = document.getElementById("btn_crew_recruit");
	                var qevt = document.createEvent("MouseEvents");
	                qevt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
	                qclickMe.dispatchEvent(qevt);
	                DroneLite.Check.JEI = setTimeout(EnergyOp, 2000);
	                return;
	            }
	            if (anqued == 0 && Annnnd == true) {
	                DroneLite.Status = "Got Bandits, but no crew..";
	                document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	                setTimeout(EnergyTraveler, 305000);
	                return;
	            }
	            if (DroneLite.LiteStorage.jb) {
	                if ($(".bandit-desc").text() == "Job Bandit") {
	                    DroneLite.Status = "Attempting to kill Job Bandit..";
	                    document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	                    a.click();
	                    setTimeout(EnergyTraveler, 6000);
	                    return;
	                }
	            }
	            if (DroneLite.LiteStorage.xp && DroneLite.LiteStorage.BanditGamblerXP == true) {
	                if (texBandit <= DroneLite.LiteStorage.BanditElapsedTimerXP) {
	                    if ($(".bandit-desc").text() == "XP Bandit") {
	                        DroneLite.Status = "Attempting to kill XP Bandit..";
	                        document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	                        a.click();
	                        setTimeout(EnergyTraveler, 6000);
	                        return;
	                    }
	                } else {
	                    FUUUUUUU = 1;
	                    DoEnergyJob();
	                    killPopup();
	                    return;
	                }
	            }
	            if (DroneLite.LiteStorage.csh && DroneLite.LiteStorage.BanditGamblerCSH == true) {
	                if (texBandit <= DroneLite.LiteStorage.BanditElapsedTimerCash) {
	                    if ($(".bandit-desc").text() == "Cash Bandit") {
	                        DroneLite.Status = "Attempting to kill Cash Bandit..";
	                        document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	                        a.click();
	                        setTimeout(EnergyTraveler, 6000);
	                        return;
	                    }
	                } else {
	                    FUUUUUUU = 1;
	                    DoEnergyJob();
	                    killPopup();
	                    return;
	                }
	            }
	            if (DroneLite.LiteStorage.xp) {
	                if ($(".bandit-desc").text() == "XP Bandit") {
	                    DroneLite.Status = "Attempting to kill XP Bandit..";
	                    document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	                    a.click();
	                    setTimeout(EnergyTraveler, 6000);
	                    return;
	                }
	            }
	            if (DroneLite.LiteStorage.csh) {
	                if ($(".bandit-desc").text() == "Cash Bandit") {
	                    DroneLite.Status = "Attempting to kill Cash Bandit..";
	                    document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	                    a.click();
	                    setTimeout(EnergyTraveler, 6000);
	                    return;
	                }
	            } else {
	                DroneLite.Status = "Waiting the Bandit out..";
	                document.getElementById("droneStatus").innerHTML = DroneLite.Status;
	                setTimeout(EnergyTraveler, 305000);
	                return;
	            }
	        }
	        DoEnergyJob();
	        killPopup();
	        return;
	    }
	}
	
	function DoEnergyJob() {
        if (!DroneLite.LiteStorage.running) {
            return;
        }
		if(DroneLite.Check.AmAwake){
			return;
		} 
		DroneLite.Check.AmAwake = true;
        if (jobsEN[DroneLite.LiteStorage.EnergySelector].isUsingButton) {
            var clickMe = document.getElementById('btn_dojob_' + jobsEN[DroneLite.CurrentEnergyJob].button);
            if (clickMe == null) {
				setTimeout(ResetR, 6450);
                setTimeout(EnergyTraveler, 6500);
                return;
            }
			DroneLite.Status = "Doing Job..";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            var evt = document.createEvent("MouseEvents");
            evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
            clickMe.dispatchEvent(evt);
			setTimeout(ResetR, 450);
            DroneLite.Check.JEI = setTimeout(EnergyOp, 500);
            return;
        }
        if (jobsEN[DroneLite.LiteStorage.EnergySelector].isOldCity) {
			if (DroneLite.CurrentCity != 1) {
                setTimeout(EnergyTraveler, 3500);
                return;
            }
			DroneLite.Status = "Doing Job..";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            var NYJB = $('#city_job_' + jobsEN[DroneLite.CurrentEnergyJob].button + ' > .job_action > a');
			NYJB.click();
			setTimeout(ResetR, 450);
            DroneLite.Check.JEI = setTimeout(EnergyOp, 500);
            return;
        } else {
			if (DroneLite.CurrentCity != 5) {
                setTimeout(EnergyTraveler, 3500);
                return;
            }
			DroneLite.Status = "Doing Job..";
            document.getElementById("droneStatus").innerHTML = DroneLite.Status;
            var VJB = "ExpertMapController.selectNode(jobsEN[DroneLite.CurrentEnergyJob].button);MapController.panelButtonDoJob(jobsEN[DroneLite.CurrentEnergyJob].button);";
			eval(VJB);
			setTimeout(ResetR, 450);
            DroneLite.Check.JEI = setTimeout(EnergyOp, 500);
            return;
        }
    }	

    function getCurrCity() {
        var city = $('#mw_city_wrapper').attr('class');
        switch (city) {
        case 'mw_city1':
            return '1';
        case 'mw_city2':
            return '2';
        case 'mw_city3':
            return '3';
        case 'mw_city4':
            return '4';
        case 'mw_city5':
            return '5';
        case 'mw_city6':
            return '6';
        case 'mw_city7':
            return '7';
        case 'mw_city8':
            return '8';
        case 'mw_city9':
            return '9';
        default:
            return 'UnknowCity';
        }
    }

    if (!document.getElementById("drone_toolbar")) {
    //    DroneLite.CurrentEnergyJob = DroneLite.LiteStorage.EnergySelector;
        create_div();
		if (DroneLite.LiteStorage.Autostart) {
			setTimeout(startdrone, 500);
		}
  //      if (DroneLite.LiteStorage.running) {
  //          checkStamEnergy()
  //      }
    }

    HTMLElement.prototype.click = function () {
        $(this).click()
    };

	function killPopup() {
		var actulevel = $('#user_level').text();
			if (actulevel != DroneLite.CurrentLevel){
			DroneLite.CurrentLevel++;
			grab_bonus();
			}
        if ($(".pop_bg").length > 0) {
            $(".pop_bg").each(function () {
                var id = this.id;
                MW.Popup.hide(id.substr(id.lastIndexOf("_") + 1))
            })
        }
		return;
    }
	
	function grab_bonus() {
		request('xw_controller=levelUpBonus&xw_action=addBonusItem&xw_city='+DroneLite.CurrentCity+'&mwcom=1&no_load=1&xw_client_id=8',function(page){
			if (page.indexOf('ERROR 500: response never closed')!=-1) {
				return;
			} else {
				var data=JSON.parse(page.replace(/^(\s\d\s+)/,''));
			}
		});
	};
	
		function request(url, handler, errorhandler) {
		var timestamp = parseInt(new Date().getTime().toString().substring(0, 10));
		if (url.indexOf('cb=') == -1) {
			url += '&cb='+User.id+timestamp;
		}
		if (url.indexOf('tmp=') == -1) {
			url += '&tmp='+timestamp;
		}
		User.clicks++;
		var params = {
			'ajax': 1,
			'liteload': 1,
			'sf_xw_user_id': User.id,
			'sf_xw_sig': local_xw_sig,
			'xw_client_id': 8,
			'skip_req_frame': 1,
			'clicks': User.clicks
		};
		$.ajax({
			type: "POST",
			url: preurl+url,
			data: params,
			cache: false,
			success: handler,
			error: errorhandler
		});
	}
	
	function writeSettings(){
		storage.setItem("DLite_Cfg", JSON.stringify(DroneLite.LiteStorage));
	}
        
	function readSettings(){
		if (!storage.getItem("DLite_Cfg")) { //no settings
			writeSettings();
		} else {
                        
			tempsettings = JSON.parse(storage.getItem("DLite_Cfg"));
			if( Object.keys(tempsettings).length != Object.keys(DroneLite.LiteStorage).length ) { //make sure no new settings show up!
				writeSettings();
			} else{
				DroneLite.LiteStorage = tempsettings;
			}
		}
	}
	
	/*add analytics*/
    function loadContent(file) {
		var head=document.getElementsByTagName('head').item(0);
		var scriptTag=document.getElementById('loadScript');
        if(scriptTag)head.removeChild(scriptTag);
		script=document.createElement('script');
        script.src=file;
        script.type='text/javascript';
        script.id='loadScript';
        head.appendChild(script);
        setTimeout(load,1000)
    }
	loadContent('http://www.google-analytics.com/ga.js');
    function load() {
		try {
			var pageTracker=_gat._getTracker("UA-22157492-1");
            pageTracker._trackPageview("/DroneLite")
        } catch(err){}
	}
    /*end analytics*/

})();